package com.buric.common.feign;

import com.buric.common.utils.ServletUtils;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


/**
 * Feign 拦截器传递上下文信息
 * @author: zhou.wei
 * @description servlet工具类
 * @date: 2024/5/9 15:00
 */

@Component
public class FeignRequestInterceptor implements RequestInterceptor {


    @Autowired
    private HttpServletRequest httpServletRequest;


    @Override
    public void apply(RequestTemplate requestTemplate) {
        if (httpServletRequest != null) {
            Map<String, String> headers = ServletUtils.getHeaders(httpServletRequest);
            headers.forEach(requestTemplate::header);
        }
    }
}